<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>表格</title>
	<style>
		.aaa0{
			background-color: pink;
			color: #fff;
		}
		.aaa1{
			background-color: #17d517;
			color: #fff;
		}
		
	</style>
	}
</head>
<body>
	<script type="text/javascript">
		var data=[
		{
			name: "姓名",
			age:"年龄",
			grade:"段位",
			sex:"性别",
		 },
		{
			name: "张三",
			age:18,
			grade:"黄金",
			sex:"男",
		 },
		 {
		 	name:"李四",
			age:19,
			grade:"钻石",
			sex:"女",
		},
		{
			name:"老王",
			age:45,
			grade:"青铜",
			sex:"男",
		},
		{
			name:"老李",
			age:33,
			grade:"王者",
			sex:"男",
		}
		];	 
		
		
			var html="<table border=1>";

            for(var i in data){

           
            html+="<tr class='aaa"+(i%2)+"'>";

			for(var j in data[i]){
				html+="<td>";
				html+=data[i][j];
				html+="</td>";
			}
				html+="</tr>";
			}
			html+="</table>";
			document.body.innerHTML=html;
	</script>
</body>
</html>